﻿using MN.Framework.Common;
using MN.Framework.Common.Service;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace MN.Framework.UI.Win.Controls
{
    public class IndexPanel : Panel
    {
        BaseContext Context { get; set; }
        public IndexPanel(BaseContext context, List<Type> indexEntities, int width)
        {
            this.Width = width;

            InitializeComponent();
            int row = 2;
            foreach (var entityType in indexEntities)
            {
                var entityCount = context.Set(entityType).AsEnumerable().Count();
                var entityTitle = ServiceFactory.Create<BaseEntity>(entityType).getTitle();
                rightLayout.Controls.Add(new Label() { Height = 30, Width = 160, Text = entityTitle }, 0, row);
                rightLayout.Controls.Add(new Label() { Width = 200, Text = entityCount.ToString() }, 1, row++);
            }
        }
        #region Events
        private void InitializeComponent()
        {
            this.radCalendar1 = new Telerik.WinControls.UI.RadCalendar();
            //this.radClock1 = new Telerik.WinControls.UI.RadClock(); ;
            this.lblInfo = new Telerik.WinControls.UI.RadLabel();
            this.mainLayout = new TableLayoutPanel();
            this.rightLayout = new TableLayoutPanel();
            this.leftLayout = new TableLayoutPanel();

            // 
            // radCalendar1
            // 
            //this.radCalendar1.Location = new System.Drawing.Point(10, 160);
            this.radCalendar1.Name = "radCalendar1";
            this.radCalendar1.Size = new System.Drawing.Size(257, 227);
            this.radCalendar1.TabIndex = 0;
            this.radCalendar1.Text = "radCalendar1";
            this.radCalendar1.Culture = new PersianCulture();
            // 
            // radClock1
            // 
            //this.radClock1.Location = new System.Drawing.Point(61, 8);
            //this.radClock1.Name = "radClock1";
            //this.radClock1.Size = new System.Drawing.Size(134, 135);      
            //this.radClock1.Text = "radClock1";
            // 
            // lblInfo
            // 
            this.lblInfo.Font = new System.Drawing.Font("Segoe UI", 8.25F, System.Drawing.FontStyle.Bold);
            //this.lblInfo.Location = new System.Drawing.Point(638, 12);
            this.lblInfo.Name = "lblInfo";
            this.lblInfo.TabIndex = 3;
            this.lblInfo.Height = 50;
            this.lblInfo.Text = "وضعیت داده های موجود";
            this.lblInfo.Width = Width - 300;
            // this             
            this.Dock = DockStyle.Fill;
            this.RightToLeft = System.Windows.Forms.RightToLeft.Yes;

            rightLayout.Width = this.Width - 300;
            rightLayout.MinimumSize = new System.Drawing.Size(400, 370);
            rightLayout.Controls.Add(this.lblInfo, 0, 0);
            rightLayout.Controls.Add(new Label() { Text = "نام موجودیت" }, 0, 1);
            rightLayout.Controls.Add(new Label() { Text = "تعداد درج شده" }, 1, 1);

            leftLayout.Width = 300;
            leftLayout.Height = 370;
            //leftLayout.Controls.Add(this.radClock1, 0, 0);
            leftLayout.Controls.Add(this.radCalendar1, 0, 1);

            mainLayout.Dock = DockStyle.Fill;
            mainLayout.Controls.Add(this.rightLayout, 0, 0);
            mainLayout.Controls.Add(this.leftLayout, 1, 0);

            this.Controls.Add(mainLayout);

        }
        #endregion

        private TableLayoutPanel mainLayout;
        private TableLayoutPanel rightLayout;
        private TableLayoutPanel leftLayout;
        private Telerik.WinControls.UI.RadCalendar radCalendar1;
        //private Telerik.WinControls.UI.RadClock radClock1;
        private Telerik.WinControls.UI.RadLabel lblInfo;

    }

}
